package com.example.newspublish.config;
import io.minio.MinioClient;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.Assert;

@Configuration
public class MinioConfig {

    @Value("${minio.access-key}")
    private String accessKey;

    @Value("${minio.secret-key}")
    private String secretKey;

    @Value("${minio.endpoint}")
    private String endpoint;

//    @Value(value = "${minio.url}")
//    private String url;
//
//    @Value(value = "${minio.endpoint}")
//    private String host;

//    private MinioClient minioClient;

    @Bean
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(accessKey, secretKey)
                .build();
    }


//    @Override
//    public void afterPropertiesSet() throws Exception {
//        Assert.hasText(url, "Minio url 为空");
//        Assert.hasText(accessKey, "Minio accessKey为空");
//        Assert.hasText(secretKey, "Minio secretKey为空");
//        this.minioClient = new MinioClient(this.host, this.accessKey, this.secretKey);
//    }

}
